package com.wl.mvi.main.tab

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.recyclerview.widget.LinearLayoutManager
import com.wl.lib.widget.RecyclerAdapter
import com.wl.mvi.databinding.BlogTabListBinding


/**
 *
 * Created by wangliang on 2024/12/3
 */
class TabTwoView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

    private val binding = BlogTabListBinding.inflate(LayoutInflater.from(context), this)

    private val adapter: RecyclerAdapter by lazy {
        RecyclerAdapter().apply {
            registerViewType<TabTwoItemView, TabTwoItem> { itemView, item, _ ->
                itemView.render()
            }
        }
    }

    init {
        binding.recyclerView.layoutManager = LinearLayoutManager(context)
        binding.recyclerView.adapter = adapter
    }

    fun render(data: TabTwo) {
        adapter.data.clear()
        adapter.data.addAll(data.list)
        adapter.notifyDataSetChanged()
    }
}